//
//  UIView+Util.m
//  SCU
//
//  Created by cctvbop on 13-8-22.
//  Copyright (c) 2013年 cctvbop. All rights reserved.
//

#import "UIView+Util.h"

@implementation UIView (Util)

- (void)removeAllSubviews
{
    for (UIView *subView in self.subviews) {
        [subView removeFromSuperview];
    }
}

- (void)removeSelf
{
    [self removeFromSuperview];
}

- (void)clearBackgroundColor
{
    self.backgroundColor = [UIColor clearColor];
}

+ (UIView*)createLineWithWidth:(CGFloat)width height:(CGFloat)height color:(UIColor *)color
{
    CGRect frame = CGRectMake(0, 0, width, height);
    UIView *lineView = [[UIView alloc] initWithFrame:frame];
    [lineView setBackgroundColor:color];
    return lineView;
}

- (void)circleView
{
    self.contentMode = UIViewContentModeScaleAspectFill;
    self.layer.masksToBounds = YES;
    self.layer.cornerRadius = self.frame.size.width / 2;
}

- (void)circleView:(CGFloat)borderWidth color:(UIColor*)color
{
    [self circleView];
    self.layer.borderWidth = borderWidth;
    self.layer.borderColor = color.CGColor;
}

- (UIAlertView *)showAlert:(NSString *)title message:(NSString *)message;
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:nil otherButtonTitles:nil, nil];
    [alertView show];
    return alertView;
}

- (UIAlertView *)showAlertOk:(NSString *)title message:(NSString *)message;
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
    [alertView show];
    return alertView;
}

- (void)showAlert:(NSString *)title message:(NSString *)message delay:(NSTimeInterval)delay;
{
    UIAlertView *alertView = [self showAlert:title message:message];
    [alertView performSelector:@selector(dismissWithClickedButtonIndex:animated:) withObject:nil afterDelay:delay];
}

- (UIButton *)showRemindButtonWithImg:(NSString *)img
{
    UIButton * button = [[UIButton alloc] initWithFrame:[UIScreen mainScreen].bounds];
    [button setBackgroundImage:[UIImage imageNamed:img] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(removeSelf) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:button];
    return button;
}

- (UIView *)circleCorner:(UIRectCorner)corners cornerRadii:(CGSize)cornerRadii
{
    UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.bounds byRoundingCorners:corners cornerRadii:cornerRadii];
    CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
    maskLayer.frame = self.bounds;
    maskLayer.path = maskPath.CGPath;
    maskLayer.strokeColor = [UIColor clearColor].CGColor;
    maskLayer.masksToBounds = YES;
    self.layer.mask = maskLayer;
    return self;
}

@end
